package cn.itcast.service.impl;

import cn.itcast.dao.ArchiveRepository;
import cn.itcast.domain.Archive;
import cn.itcast.service.ArchiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author： ~Mr·Weng~
 * @CreateTime： 2019年-04月-21日  3:56
 * Look at the wine in the glass toast the rich first.
 */
@Service
public class ArchiveServiceImpl implements ArchiveService{



    private ArchiveRepository archiveRepository;
    //构造函数依赖注入
    @Autowired
    public ArchiveServiceImpl(ArchiveRepository archiveRepository) {
        this.archiveRepository = archiveRepository;
    }

    //查询全部基础档案设置
    @Override
    public Page<Archive> pageQuery(int page, int rows) throws Exception{
        PageRequest pageable = PageRequest.of(page-1, rows);
        Page<Archive> archivePage = archiveRepository.findAll(pageable);
        if (archivePage.getSize()==0){
            throw new Exception("没查到数据");
        }
        return archivePage;
    }
}
